package com.ayuer.chapter01;

public class RecursionAlgoDemo02 {


    private static int f(int[] arr, int target, int start, int end) {
        //start 和 end
        if (start > end) {
            return -1;
        }
        int middle = start + (end - start) / 2;
        if (target < arr[middle]) {
            end = middle - 1;
            return f(arr, target, start, end);
        } else if (target > arr[middle]) {
            start = middle + 1;
            return f(arr, target, start, end);
        } else {
            return middle;
        }
    }

    private static int getRes(int[] arr01, int target) {
        int res = f(arr01, target, 0, arr01.length - 1);
        return res;
    }

    public static void main(String[] args) {
        int[] arr01 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int res = getRes(arr01, 9);
        System.out.println(res);
    }
    
}
